<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>添加维修记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/layui/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="width: 100%;" id="dataFrm">
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">车牌号:</label>
        <div class="layui-input-block">
            <select id="carNo"  name="car.id" class="carNo" lay-filter="carNo">
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">维修厂:</label>
        <div class="layui-input-block">
            <select id="repairNo"  name="currentUnit.id" class="repairNo" lay-filter="repairNo">
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">送修时间:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input send_time" name="send_time" lay-verify="required" placeholder="请输入送修时间">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label" style="white-space:nowrap">预计取车日期:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input estimate_time" name="estimate_time" lay-verify="required" placeholder="请输入预计取车日期">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">送修原因:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input send_reason" name="send_reason" lay-verify="required" placeholder="请输入送修原因">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">送修备注:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input send_remarks" name="send_remarks" lay-verify="required" placeholder="请输入送修备注">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">经办人:</label>
        <div class="layui-input-block">
            <select id="userNo" name="user.id" class="userNo" lay-filter="userNo">
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">维修类型:</label>
        <div class="layui-input-block">
            <select id="repairTypeNo" name="dictionary.id" class="repairTypeNo" lay-filter="repairTypeNo">
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">取车日期:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input get_time" name="get_time" lay-verify="required" placeholder="请输入取车日期">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">维修费用:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input repair_cost" name="repair_cost" lay-verify="required" placeholder="请输入维修费用">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">维修项目:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input repair_option" name="repair_option" lay-verify="required" placeholder="请输入维修项目">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">使用材料:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input use_stuff" name="use_stuff" lay-verify="required" placeholder="请输入使用材料">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">取车备注:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input get_remarks" name="get_remarks" lay-verify="required" placeholder="请输入取车备注">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="add">立即添加</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary" id="esc">取消</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="resources/layui/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl','upload'],function() {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
            upload=layui.upload;
        //生日框的时间插件绑定
        laydate.render({
            elem: ".send_time,.estimate_time,.get_time" ,//指定元素
            //type:'datetime'
        });
        //请求获取数据
        //动态绑定下拉菜单的数据
        var cars;
        $.ajax({
            url:'/repairRecords/cars.do',
            success:function (data) {
                cars += "<option value=''>------------请选择------------</option>"
                for (i = 0; i < data.length; i++) {
                    cars += ("<option value='" + data[i].id + "'>" + data[i].car_no + "</option>")
                }
                $("#carNo").append(cars);
                form.render('select');
            }
        });
        var repairs;
        $.ajax({
            url:'/repairRecords/repairs.do',
            success:function (data) {
                repairs += "<option value=''>------------请选择------------</option>"
                for (i = 0; i < data.length; i++) {
                    repairs += ("<option value='" + data[i].id + "'>" + data[i].unit_name + "</option>")
                }
                $("#repairNo").append(repairs);
                form.render('select');
            }
        });
        var users;
        $.ajax({
            url:'/repairRecords/users.do',
            success:function (data) {
                users += "<option value=''>------------请选择------------</option>"
                for (i = 0; i < data.length; i++) {
                    users += ("<option value='" + data[i].id + "'>" + data[i].rname + "</option>")
                }
                $("#userNo").append(users);
                form.render('select');
            }
        });
        var repairTypes;
        $.ajax({
            url:'/repairRecords/repairTypes.do',
            success:function (data) {
                repairTypes += "<option value=''>------------请选择------------</option>"
                for (i = 0; i < data.length; i++) {
                    repairTypes += ("<option value='" + data[i].id + "'>" + data[i].name + "</option>")
                }
                $("#repairTypeNo").append(repairTypes);
                form.render('select');
            }
        });

        form.on("submit(add)",function (data) {
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            //实际使用时的提交数据
            var params=$("#dataFrm").serialize();
            console.log(params);
            $.post("/repairRecords.do",params,function (res) {
                console.log(res.code);
                layer.msg(res.msg);
                if(res.code==1011){
                    console.log("***************");
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    var index1=parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index1);
                    parent.location.reload();
                }
            },"json");
            return false;
        });
        $("#esc").click(function () {
            var index1=parent.layer.getFrameIndex(window.name)
            parent.layer.close(index1);
        });
    })
</script>
</body>
</html>